package com.ihr360.payroll.model.dto.salary.plan.payslip;

import com.ihr360.commons.model.entity.NumberId;
import lombok.Data;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;

/**
 * @author tomtao
 */
@Data
@Entity
public class PayrollMergeField extends NumberId<Long> {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private PayrollMergeSetting setting;

    /**
     * 名称
     */
    @Column(nullable = false, length = 50)
    private String name;

    /**
     * 公式
     */
    @Column(nullable = false, length = 1000)
    protected String formula;

    /**
     * 序号
     */
    protected int indexno = 1;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "mergeField", cascade = CascadeType.ALL, orphanRemoval = true)
    protected List<PayrollMergeFieldFormulaItem> formulaItems = new ArrayList<>();

}
